package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 计划状态枚举
 *
 * @author S-01 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
public enum PlanStatus implements BaseEnum {
    DRAFT("draft", "草稿"),
    PENDING("pending", "待处理"),
    APPROVED("approved", "已批准"),
    REJECTED("rejected", "已拒绝"),
    ACTIVE("active", "激活"),
    INACTIVE("inactive", "未激活"),
    COMPLETED("completed", "已完成"),
    CANCELLED("cancelled", "已取消"),
    SUSPENDED("suspended", "已暂停"),
    ARCHIVED("archived", "已归档"),
    UNDER_REVIEW("under_review", "审核中"),
    SCHEDULED("scheduled", "已安排"),
    IN_PROGRESS("in_progress", "进行中"),
    FAILED("failed", "失败"),
    POSTPONED("postponed", "延期"),
    EXPIRED("expired", "已过期");

    private final String code;
    private final String description;

    PlanStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static PlanStatus fromCode(String code) {
        for (PlanStatus status : PlanStatus.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("未知的计划状态代码: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static PlanStatus fromDescription(String description) {
        for (PlanStatus status : PlanStatus.values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("未知的计划状态描述: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}